package com.yanqu.road.server.cmd.activity.recallplayer;


import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.recallplayer.RecallPlayerModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_RECALL_PLAYER_BIND_TASK_FINISH, desc = "完成绑定任务")
public class RecallPlayerFinishBindTaskCmd extends AbstractCommand {

    private int taskId;
    private long bindUserId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RecallPlayerProto.UserFinishTaskReqMsg msg = RecallPlayerProto.UserFinishTaskReqMsg.parseFrom(packet.getBytes());
        taskId = msg.getTaskId();
        bindUserId = msg.getBindUserId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(RecallPlayerModule.class).finishBindTask(taskId, bindUserId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            RecallPlayerProto.UserFinishTaskRespMsg.Builder builder = RecallPlayerProto.UserFinishTaskRespMsg.newBuilder();
            builder.setRet(ret);
            builder.setReward("");
            player.sendPacket(ClientProtocol.U_RECALL_PLAYER_BIND_TASK_FINISH, builder);
        }

    }
}
